﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Students
    {
        public int Id { get; set; }
        public int StudyId { get; set; }
        public int BlockId { get; set; }
        public string StudyOther { get; set; }
        public int UniversityNV1Id { get; set; }
        public int StudyNV1Id { get; set; }
        public int BlockNV1Id { get; set; }
        public string StudyOtherNV1 { get; set; }
        public bool IsLienThong { get; set; }
        public string LastName { get; set; }
        public string FullName { get; set; }
        public bool Gender { get; set; }
        public DateTime BirthDay { get; set; }
        public string BirthPlace { get; set; }
        public int EthnicId { get; set; }
        public int PriorityId { get; set; }
        public string HoKhau { get; set; }
        public int ProvinceId { get; set; }
        public int DistrictId { get; set; }
        public int Province10Id { get; set; }
        public int HighSchool10Id { get; set; }
        public int Province11Id { get; set; }
        public int HighSchool11Id { get; set; }
        public int Province12Id { get; set; }
        public int HighSchool12Id { get; set; }
        public int ZoneId { get; set; }
        public string YearGraduation { get; set; }
        public int UniversityCD { get; set; }
        public string YearGraduationCD { get; set; }
        public string PlaceOfHoSo { get; set; }
        public int IdDonVi { get; set; }
        public string CumThi { get; set; }
        public string CardNo { get; set; }
        public string ContactAddress { get; set; }
        public string Mobile { get; set; }
        public DateTime DateOfHoSo { get; set; }
         private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public Students()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }
        public int Insert(Students obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO  Students (StudyId, BlockId,StudyOther, UniversityNV1Id, StudyNV1Id,BlockNV1Id," +
                                       "StudyOtherNV1, IsLienThong, LastName, FullName,Gender, BirthDay,BirthPlace,EthnicId, PriorityId,HoKhau, " +
                                       "ProvinceId,DistrictId,Province10Id,HighSchool10Id,Province11Id,HighSchool11Id,Province12Id,HighSchool12Id," +
                                       "ZoneId,YearGraduation,UniversityCD, YearGraduationCD, PlaceOfHoSo, IdDonVi, CumThi,CardNo, " +
                                       "ContactAddress, Mobile, DateOfHoSo) values ('{0}', '{1}', N'{2}', '{3}', '{4}'," +
                                       " '{5}', N'{6}', N'{7}', N'{8}', N'{9}', N'{10}', '{11}', N'{12}', '{13}'," +
                                       " '{14}', N'{15}', '{16}', '{17}', '{18}', '{19}', '{20}', '{21}', '{22}', " +
                                       "'{23}', '{24}', N'{25}', N'{26}', N'{27}', N'{28}', '{29}', N'{30}'," +
                                       " N'{31}', N'{32}', N'{33}', '{34}')"
                                       , obj.StudyId, obj.BlockId, obj.StudyOther, obj.UniversityNV1Id, obj.StudyNV1Id, 
                                       obj.BlockNV1Id, obj.StudyOtherNV1, obj.IsLienThong, obj.LastName, obj.FullName,
                                       obj.Gender, obj.BirthDay, obj.BirthPlace, obj.EthnicId, obj.PriorityId, obj.HoKhau, 
                                       obj.ProvinceId, obj.DistrictId, obj.Province10Id, obj.HighSchool10Id, obj.Province11Id,
                                       obj.HighSchool11Id, obj.Province12Id, obj.HighSchool12Id, obj.ZoneId, obj.YearGraduation, 
                                       obj.UniversityCD, obj.YearGraduationCD, obj.PlaceOfHoSo, obj.IdDonVi, obj.CumThi, obj.CardNo, 
                                       obj.ContactAddress, obj.Mobile, obj.DateOfHoSo);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Students obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE  Students SET StudyId='{0}', BlockId='{1}',StudyOther= N'{2}', UniversityNV1Id='{3}'," +
                                       "StudyNV1Id=N'{4}', BlockNV1Id='{5}', StudyOtherNV1=N'{6}',IsLienThong='{7}',LastName= N'{8}',FullName= N'{9}', " +
                                       "Gender= '{10}', BirthDay='{11}', BirthPlace=N'{12}',EthnicId=N'{13}',PriorityId='{14}', HoKhau=N'{15}'," +
                                       " ProvinceId='{16}',DistrictId= '{17}',Province10Id='{18}', HighSchool10Id='{19}', Province11Id='{20}'," +
                                       "HighSchool11Id='{21}',Province12Id='{22}', HighSchool12Id='{23}',ZoneId='{24}',YearGraduation= N'{25}', " +
                                       "UniversityCD='{26}', YearGraduationCD=N'{27}',PlaceOfHoSo= N'{28}', IdDonVi=N'{29}',CumThi= N'{30}'," +
                                       " CardNo=N'{31}', ContactAddress=N'{32}', Mobile=N'{33}',DateOfHoSo='{34}' WHERE ID='{35}'"
                                       , obj.StudyId, obj.BlockId, obj.StudyOther, obj.UniversityNV1Id, obj.StudyNV1Id, 
                                       obj.BlockNV1Id, obj.StudyOtherNV1, obj.IsLienThong, obj.LastName, obj.FullName,
                                       obj.Gender, obj.BirthDay, obj.BirthPlace, obj.EthnicId, obj.PriorityId, obj.HoKhau, 
                                       obj.ProvinceId, obj.DistrictId, obj.Province10Id, obj.HighSchool10Id, obj.Province11Id, 
                                       obj.HighSchool11Id, obj.Province12Id, obj.HighSchool12Id, obj.ZoneId, obj.YearGraduation,
                                       obj.UniversityCD, obj.YearGraduationCD, obj.PlaceOfHoSo, obj.IdDonVi, obj.CumThi, 
                                       obj.CardNo, obj.ContactAddress, obj.Mobile, obj.DateOfHoSo,obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
        public int Delete(Students obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Students  Where id= '{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}